package com.example.controller;

import com.example.service.TestService;
import lombok.Builder;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class HelloController {

    @Autowired
    private TestService testService;

    @GetMapping("hello1")
    public String hello(){
        testService.test();
        return "Hello World";
    }

    @GetMapping("hello2")
    public String hello(@RequestParam("name") String name){
        return "Hello " + name;
    }

    @PostMapping("login")
    public String helloPost(LoginData loginData){
        return loginData.getUsername() + "" + loginData.getPassword();
    }

    @PostMapping("loginData")
    public String login(@RequestBody LoginData loginData){
        return loginData.getUsername() + "" + loginData.getPassword();
    }

    @GetMapping("get/{id}")
    public String get(@PathVariable("id") Integer id){
        return "id: " + id;
    }

    @PostMapping("post/{id}")
    public String post(@PathVariable("id") Integer id){
        return "id: " + id;
    }


    @GetMapping("getR")
    public R succ(){
        return R.builder()
                .code(0)
                .build();
    }


    @Data
    @Builder
    public static class R{
        private int code;
        private String msg;
        private String data;
    }

    @Data
    public static class LoginData{
        private String username;
        private String password;
    }


}
